﻿using System.IO;

using NUnit.Framework;
using Ninject;

using System.Net.DnsToolkit.Bastard.PacketGenerator;
using System.Net.DnsToolkit.Configuration;
using System.Net.DnsToolkit.Packet;
using System.Net.DnsToolkit.Serializer;

namespace System.Net.DnsToolkit.TestUnit.Bastard.PacketGenerator {

    [TestFixture]
    public class HugeQuestionPacketTest {

        [Test]
        public void TestDefault() {

            var generator = new HugeQuestionPacket();
            var message = generator.GetMessage();
            byte[] bs = generator.GetBytes();

            Assert.AreEqual(49, message.Questions.Count, "Questions.Count");
            Assert.AreEqual(49, message.Header.QuestionCount, "Header.QuestionCount");
            Assert.AreEqual(510, bs.Length, "bs");
        }

        [Test]
        public void Test10000() {
            ushort qcount = 10000;
            var generator = new HugeQuestionPacket(qcount, "host");
            var message = generator.GetMessage();

            Assert.AreEqual(qcount, message.Questions.Count, "Questions.Count");
            Assert.AreEqual(qcount, message.Header.QuestionCount, "Header.QuestionCount");
        }

        [Test]
        public void Test() {
            var generator = new HugeQuestionPacket(1000);
            var message = generator.GetMessage();
            int i = 0;
            message.Questions.ForEach(
                q => Assert.AreEqual(string.Format("h{0}.localhost.localnet", i++), q.QName.Name, "Question.Name")
            );
            Assert.AreEqual(i, 1000, "Questions.Count");
        }


        [Test]
        public void TestGetBytes() {

            var generator = new HugeQuestionPacket(1000);
            byte[] bs = generator.GetBytes();
            Assert.AreEqual(10920, bs.Length, "length");

        }

        [Test]
        public void TestGetBytes510() {

            var generator = new HugeQuestionPacket(49);
            byte[] bs = generator.GetBytes();
            Assert.AreEqual(510, bs.Length, "length");

        }

        private IKernel _kernel;
        [TestFixtureSetUp]
        public void Setup() {
            _kernel = new StandardKernel(new DnsWriterStreamModule());
        }


    }
}
